package com.dyh.quickdemo.depRm2;


import com.alibaba.fastjson.JSON;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect //声明切面
@Component //让spring容器管理
public class EnhanceMethodAspect {

    public static final Logger log =
            LoggerFactory.getLogger(EnhanceMethodAspect.class);



    @Around("@annotation(com.dyh.quickdemo.depRm2.Enhance)")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {


        //throw new GlobalException(CodeVErrorMsg.REQ_NULL());//此处抛异常也可被全局处理拦截

        MethodSignature ms = (MethodSignature) pjp.getSignature();
        Method method = ms.getMethod();

        Enhance logDangerMethod = method.getAnnotation(Enhance.class);


        String methodName =    pjp.getTarget().getClass()+"."+ ms.getName();
//        Object result = 1L;
        Object result = "fu";
        return result;
//        // 执行目标
//        Object result = null;
//        boolean hasException = false;
//        Throwable throwable =null;
//
//        try {
//            result = pjp.proceed();
//        } catch (Throwable th) {
//            log.error("方法:{}参数:{}异常:",
//                    methodName, JSON.toJSON(pjp.getArgs())
//                            ,th
//            );
//            hasException = true;
//            throwable = th;
//        }


   //     return result;

    }



}
